/**************************************************************************
 * @doc pfr
 * @module pfr.h
 * Include for the power failure recovery module.
 *
 * Product     :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :   Bruce Girdlestone
 * <nl>Notes       :
 *
 * @head3 PFR Functions |
 * @index | PFR
 * @end
 *
 * Copyright (c) 1996-2000 by VeriFone Inc. All rights reserved.
 *
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form
 * or by any means whether electronic, mechanical, magnetic, optical,
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * ------------------------------------------------------------------------
 * $log: \softpay\SPK2SIM\SOURCE\POWRFAIL\PFR.h $
 * ------------------------------------------------------------------------
 ********************************************************************************/

#ifndef PFR_H
#define PFR_H
#include <pwrfids.h>
#include <transact.h>
#include <logsys.h>
//#include <logsys.h>

extern int PFR_RECOVERING;
extern char  pchFormatMessageBuf[200];


/* The power failure table structure */
typedef struct PFR_TABLE
{

	short  inStateIdentifier;
	short  inRecoveryFunctions[MAX_FUNCTION_IDS];
#ifdef __arm
	short  fill01;		// JPP
#endif
}
PFR_TABLE_STRUCT;

#if 0
/* Logfile structure */
typedef struct LOGFILE_HEADER
{
	int maxsize;
	int offset;
}
PFR_LOGFILE_HEADER_STR;
#endif

#ifndef PFR_MAX_LOGFILE_SIZE
#define  PFR_MAX_LOGFILE_SIZE 1000
#endif


#define MAX_POWER_REC_FLEXI_SIZE	3000
#define MAX_DEFAULT_DATA_FLEXI_SIZE 100
#define MAX_LINE_FLEXI_SIZE	30


/* Power failure file name */
#define POWER_FAIL_FILE_NAME	"PWRFAIL.DAT"
#define POWER_ADDITIONAL_PFR_FILE_NAME "PWRADD.DAT"
#define TRAN_OBJ_FILE_NAME	"TRANOBJ.DAT"

/*
#define PFR_DATE_SIZE 9
#define PFR_TIME_SIZE 7
*/

#ifdef _TARG_68000
#ifndef PFR_DATE_SIZE  
#define PFR_DATE_SIZE 9
#endif
#ifndef PFR_TIME_SIZE  
#define PFR_TIME_SIZE 7
#endif
#endif

#if __arm
#ifndef PFR_DATE_SIZE  
#define PFR_DATE_SIZE 12
#endif
#ifndef PFR_TIME_SIZE  
#define PFR_TIME_SIZE 8
#endif

#endif

#define POWER_FAIL_STAT_TABLE "PFR.DAT"

int PFR_CODE_CHECK(char * a,char *b,short  *  c,char * d,unsigned char * e);



/* Powerfail error handling macro */
#define PFR_HANDLE_ERROR(a) if (a != 0){return a;}


short shSetPFRState(TRANSACTION_OBJECT * tranObject,
				   short inCurrentState,
				   char chStoreTranObjFlag,
				   char chStoreExtendedData,
				   unsigned char * pvoAdditionalFlexRec);

int inInitPowerFailFile(void);

int vPFRSetPartFunc(int line);

int inGetExternalPfrData(unsigned int uiFieldId,unsigned char * pchFieldData,int inDataSize);

int inPFRExecute(void);

int inAddPFRFunctions(void);


void vLogCommS(char * message);

int inPFRStateStoreAll(int inCurrentState,
						TRANSACTION_OBJECT * pobTran,
						char chStoreTransactionObject,
						char chStoreExtendedData);

int inAddExternalPfrData(unsigned int uiFieldId,unsigned char * pchFieldData,int inDataSize);
int inPFRIdle(TRANSACTION_OBJECT * tranObject);
int inPFRStateRestoreAll(TRANSACTION_OBJECT * pobTran);
int inPFRReceiptRecoveryPending(TRANSACTION_OBJECT * tranObject);
int inPFRReceiptRecovery(TRANSACTION_OBJECT * tranObject);
int inPFRAccumRecovery(TRANSACTION_OBJECT * tranObject);
int inPFRBatchRecovery(TRANSACTION_OBJECT * tranObject);
int inPFRRecoveryCleanup(TRANSACTION_OBJECT * tranObject);
int inPrintRecoveryMessage(TRANSACTION_OBJECT * tranObject);
int inInitSettleRecovery(TRANSACTION_OBJECT * tranObject);

int inReadPFRFiledata(short * pinPFRState,
					  char * pchUpdateDate,
					  char * pchUpdateTime,
					  int * pinFailureCounter,
					  int * pinRecoveryFuncFailCount,
					  unsigned char ** pucFlexiRecBuffer);


/* Different logging mechanisms */
#define LOGSYS_NONE				0
#define LOGSYS_FILE				1
#define LOGSYS_COMM				2
#define LOGSYS_COMM_FILE		3




#define CRITICAL_ERROR			1
#define NON_CRITICAL_ERROR		2
#define NULL_POINTER_ERROR		3
#define PFR_LOG_MESSAGE			4

#ifdef __arm
static char PFR_DATE[PFR_DATE_SIZE];
static char PFR_TIME[PFR_TIME_SIZE];
#endif /* __arm */


#endif

